﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Task.Entity;
using PowerCreator.LMS.Web.Task;
using System.Collections.Generic;

public partial class sysadmin_TaskManager_ConfigureManager : PowerCreator.LMS.Web.Base.BasePage
{
    ConfigureManag objConfigureManag = new ConfigureManag();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
            InitPage();
        }
    }

    protected override void InitPage()
    {
        lbl_InfoTitle.Text = "系统参数配置";//GetLanageValueByKey("lab_ManagerPaperInfo_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
       
        base.InitPage();
    }

    private string GetSearch()
    {
        string search = " ConfigIsView=1";
        return search.ToString();
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objConfigureManag.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
      
    }

    private void BinderGV(string search, int pageIndex)
    {
 
        DataTable dt = new DataTable();
        dt = objConfigureManag.Query(search, "", LMSPageSize, pageIndex);



        //gvConfigure.Columns[5].HeaderText = GetLanageValueByKey("btn_ManagerQuestion_Work", PowerCreator.LMS.Language.LanagetItemType.Page);

        gvConfigure.DataKeyNames = new string[] {"TConfigID"};
        gvConfigure.DataSource = dt;
        gvConfigure.DataBind();





        PreAspNetPager(AspNetPager1);

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }

    protected void gvConfigure_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //string ConfigName = ((TextBox)(gvConfigure.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string ConfigValue = ((TextBox)(gvConfigure.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        int  TConfigID = int.Parse(gvConfigure.DataKeys[e.RowIndex].Value.ToString());
        Configure objConfigure= objConfigureManag.Load(TConfigID);
        //objConfigure.ConfigName = ConfigName;
        objConfigure.ConfigValue = ConfigValue;
        objConfigureManag.Update(objConfigure);

        gvConfigure.EditIndex = -1;

        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvConfigure_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvConfigure.EditIndex = -1;
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvConfigure_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvConfigure.EditIndex = e.NewEditIndex;
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
}
